package Ep06_BinaryTree.BFS.T10_0111;

import Ep06_BinaryTree.TreeNode;
import java.util.Deque;
import java.util.LinkedList;

public class Mine {
    public int minDepth(TreeNode root) {
        Deque<TreeNode> deque = new LinkedList<>();
        if (root == null) return 0;
        deque.offer(root);
        int count = 1;
        while (!deque.isEmpty()){
            int size = deque.size();
            while (size > 0){
                TreeNode tempNode = deque.poll();
                if (tempNode.left != null) deque.offer(tempNode.left);
                if (tempNode.right != null) deque.offer(tempNode.right);
                if (tempNode.left == null && tempNode.right == null) return count;
                size--;
            }
            count++;
        }
        return count;
    }
}
